var express = require('express');
var router = express.Router();
const { Server } = require('socket.io');

const io = new Server(4000, {
  cors: {
    origin: '*',
  }
});

io.on('connection', socket=> {
  console.log('connected to socket', socket.id);
  socket.on('grpc_request', message => {
    console.log({message});
    socket.emit('grpc_response', {
      message: 'this is a response from server'
    });
  });
});

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

router.post('/create', (req, res)=> {
  res.send('do create');
})

module.exports = router;
